/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.server.modules.sys.web.supplment;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.server.common.config.Global;
import com.server.common.persistence.Page;
import com.server.common.web.BaseController;
import com.server.common.utils.StringUtils;
import com.server.modules.sys.entity.supplment.TSupplmentMember;
import com.server.modules.sys.service.supplment.TSupplmentMemberService;

/**
 * 已推送消息用户记录Controller
 * @author 金小敏
 * @version 2017-03-09
 */
@Controller
@RequestMapping(value = "${adminPath}/sys/supplment/tSupplmentMember")
public class TSupplmentMemberController extends BaseController {

	@Autowired
	private TSupplmentMemberService tSupplmentMemberService;
	
	@ModelAttribute
	public TSupplmentMember get(@RequestParam(required=false) String id) {
		TSupplmentMember entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = tSupplmentMemberService.get(id);
		}
		if (entity == null){
			entity = new TSupplmentMember();
		}
		return entity;
	}
	
	@RequiresPermissions("sys:supplment:tSupplmentMember:view")
	@RequestMapping(value = {"list", ""})
	public String list(TSupplmentMember tSupplmentMember, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<TSupplmentMember> page = tSupplmentMemberService.findPage(new Page<TSupplmentMember>(request, response), tSupplmentMember); 
		model.addAttribute("page", page);
		model.addAttribute("tSupplmentMember", tSupplmentMember);
		return "modules/sys/supplment/tSupplmentMemberList";
	}

	@RequiresPermissions("sys:supplment:tSupplmentMember:view")
	@RequestMapping(value = "form")
	public String form(TSupplmentMember tSupplmentMember, Model model) {
		model.addAttribute("tSupplmentMember", tSupplmentMember);
		return "modules/sys/supplment/tSupplmentMemberForm";
	}

	@RequiresPermissions("sys:supplment:tSupplmentMember:edit")
	@RequestMapping(value = "save")
	public String save(TSupplmentMember tSupplmentMember, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, tSupplmentMember)){
			return form(tSupplmentMember, model);
		}
		tSupplmentMemberService.save(tSupplmentMember);
		addMessage(redirectAttributes, "保存已推送消息用户记录成功");
		return "redirect:"+Global.getAdminPath()+"/sys/supplment/tSupplmentMember/?repage";
	}
	
	@RequiresPermissions("sys:supplment:tSupplmentMember:edit")
	@RequestMapping(value = "delete")
	public String delete(TSupplmentMember tSupplmentMember, RedirectAttributes redirectAttributes) {
		tSupplmentMemberService.delete(tSupplmentMember);
		addMessage(redirectAttributes, "删除已推送消息用户记录成功");
		return "redirect:"+Global.getAdminPath()+"/sys/supplment/tSupplmentMember/?repage";
	}

}